# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Claudio Riva <firetux83@gmail.com>

pkgname=pdfmod
pkgver=0.9.1
pkgrel=12
pkgdesc="Simple application for modifying PDF written in C Sharp"
arch=('any')
url="https://wiki.gnome.org/Attic/PdfMod"
license=('GPL' 'MIT')
depends=('gtk-sharp-2' 'poppler-glib')
makedepends=('hyena' 'poppler-sharp' 'intltool' 'yelp-tools' 'dos2unix')
source=("https://download.gnome.org/sources/$pkgname/${pkgver%.*}/$pkgname-$pkgver.tar.bz2"
        '0001-pdfmod-mono-2.10.patch'
        '0002-fix-build.patch'
        '0003-drop-gconf-dependency.patch'
        '0004-yelp-tools.patch'
        'pdfmod.appdata.xml'
        'LICENSE-PDFsharp')
sha256sums=('eb7c987514a053106ddf03f26544766c751c801d87762909b36415d46bc425c9'
            'fad48fb68fe6a9b60032a43c6c0389092684723a3aab296e926003ff0b33880c'
            'fcf26040435b88f625d2c3b36540ea6c78e767439a6dee8d2f87119e8d666978'
            '6a235f93ce7321cbe2e7f20094ece0659fb4648602e84a4824a0fb527be90914'
            '40407ed97f2e79d5c63a9a6c67ea7c21a58b95095ba5449ff607acd5c829513a'
            '15a79778dfebed691b0a59a34e9a02bd0377012aa540ecd6ff65a5b2b969d7d5'
            '5d2b6e1a9e5582f9c5d129f222ff01ca6ce3dfa4a5c1f5c41ba827fe0fbeb4bd')

prepare() {
  cd $pkgname-$pkgver

  # Some files are distributed in DOS format
  find . -type f -exec dos2unix -q '{}' \;

  # https://bugzilla.gnome.org/show_bug.cgi?id=644516
  patch -Np1 -i ../0001-pdfmod-mono-2.10.patch

  # Workaround for build error (FS#39501)
  patch -Np1 -i ../0002-fix-build.patch

  # Remove deprecated GConf dependency
  patch -Np1 -i ../0003-drop-gconf-dependency.patch
  
  # Don't use deprecated gnome-doc-utils
  mv docs/C/{pdfmod.xml,index.docbook}
  patch -Np1 -i ../0004-yelp-tools.patch

  # Fix build
  sed -i 's/gmcs/mcs/' configure{,.ac}
  sed -i 's|pkglib_SCRIPTS|monolibdir = $(pkglibdir)/\nmonolib_DATA|' Makefile.include

  autoreconf -fi
}

build() {
  cd $pkgname-$pkgver
  ./configure \
     --prefix=/usr \
     --sysconfdir=/etc \
     --localstatedir=/var \
     --disable-scrollkeeper
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir/" install
  install -Dm0644 "$srcdir/pdfmod.appdata.xml" "$pkgdir/usr/share/metainfo/pdfmod.appdata.xml"
  install -Dm0644 "$srcdir/LICENSE-PDFsharp" "$pkgdir/usr/share/licenses/$pkgname/LICENSE-PDFsharp"
}
